<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="shortcut icon" href="../../favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
    <link rel="stylesheet" href="../../styles/common.css">
    <link rel="stylesheet" href="../../styles/register.css">
    <link rel="stylesheet" href="../../styles/icon/iconfont.css" />
    <link rel="stylesheet" href="../../styles/page.css" />
    <style>
        .body{
            min-width: 1366px;
        }

    </style>
</head>
<body>
<img src="../../images/login/login.png" id="title">
<div class="register" >
    <div class="register-box" id="register-app">
        <img src="../../images/login/login-l.png" alt="" >
            <div class="register-form" >
                <p>考生注册</p>
                <el-form ref="registerForm" :model="registerForm" label-width="180px">
                    <el-form-item label="考生姓名:" prop="name" id="item">
                        <el-input v-model="registerForm.name" placeholder="请输入考生姓名" maxlength="20"/>
                    </el-form-item>
                    <el-form-item label="手机号:" prop="phone" id="item">
                        <el-input v-model="registerForm.phone" placeholder="请输入手机号" maxlength="20"/>
                    </el-form-item>
                    <el-form-item label="密码:" prop="password" id="item">
                        <el-input v-model="registerForm.password" placeholder="请输入密码" maxlength="20"/>
                    </el-form-item>
                    <el-form-item label="性别:" prop="sex" id="item">
                        <el-radio-group v-model="registerForm.sex" id="sex">
                            <el-radio label="男"></el-radio>
                            <el-radio label="女"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item>
                        <el-button size="medium" type="primary" id="button" onclick="gotoPage()">
                            返回
                        </el-button>
                        <el-button size="medium" type="primary" id="button"
                                   @click="register('registerForm',true)">
                            注册
                        </el-button>
                    </el-form-item>
                </el-form>
            </div>
    </div>
</div>

<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../js/validate.js"></script>
<script src="../../js/index.js"></script>
<script src="../../api/register.js"></script>

<script>
    new Vue({
        el: '#register-app',
        data(){
            return {
                id:'',
                actionType:'',
                registerForm:{
                    name: '',
                    phone:'',
                    password: '',
                    sex: '男'
                }
            }
        },
        methods: {
            register (formName,st) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        const params = {
                            ...this.registerForm,
                            sex: this.registerForm.sex === '女' ? '女' : '男'
                        }
                        registerAPI(params).then(res => {
                            if (res.code === 1) {
                                this.$message.success('考生添加成功！')
                                if (!st) {
                                    this.goBack()
                                } else {
                                    this.registerForm = {
                                        'name':'',
                                        'phone':'',
                                        'password':'',
                                        'sex':'男',
                                    }
                                }
                            } else {
                                this.$message.error(res.msg || '操作失败')
                            }
                        }).catch(err => {
                            this.$message.error('请求出错了：' + err)
                        })
                    }else {
                        window.location.href= '..backend/page/register/register.html'
                    }
                })
            },
            goBack(){
                window.location.href = '..backend/page/register/register.html';
            }
        }
    })
    function gotoPage(){
        window.location.href = '../login/teacherLogin.html';
    }
</script>